<?php 

class CommonPageModel extends BaseModel
{
	private $table;
	
	/**
	 * Hold an instance of the class
	 * @var CommonPageModel
	 */
	private static $_instance = null;
	
	/**
	 * A private constructor
	 * Prevents direct creation of object
	 */
	private function __construct()
	{
		$this->_init();
		$this->table = "srcms_page";
	}

	/**
	 * The singleton method
	 * @return CommonPageModel
	 */
	public static function getInstance()
	{
		if (!self::$_instance instanceof self)
			self::$_instance = new self;

		return self::$_instance;
	}
	
	/**
	 * Returns info by id menu.
	 * 
	 * @param $id_menu
	 * @return array|DibiRow
	 */
	public function getPageInfo($id_menu){

		return dibi::query("SELECT * FROM ".$this->table." WHERE id_menu = %i", $id_menu)->fetchAll();
		
	}
	
	/**
	 * Saves info about page to Db.
	 * @param $args
	 * @return void
	 */
	public function savePage($args){
		
		$item = self::getPageInfo($args["id_menu"]);
		
		if(empty($item)) 
		dibi::query("INSERT INTO ".$this->table." ", $args);
		else
		dibi::query("UPDATE ".$this->table." SET", $args, "WHERE id_menu = %i", $args["id_menu"]);
		
	}
	
}

?>